<template>
  <el-row class="tac">
    <el-col :span="12">
      <el-menu
        active-text-color="#ffd04b"
        background-color="#545c64"
        class="el-menu-vertical-demo"
        default-active="1"
        text-color="#fff"
        @open="handleOpen"
        @close="handleClose"
        router
      >
        <el-menu-item index="1" :route="{name: 'commodity'}">
          <el-icon>
            <icon-menu/>
          </el-icon>
          <span>商品管理</span>
        </el-menu-item>
        <el-menu-item index="2" :route="{name: 'user'}">
          <el-icon>
            <user/>
          </el-icon>
          <span>用户管理</span>
        </el-menu-item>
        <el-menu-item index="3" :route="{name: 'user'}">
          <el-icon>
            <document/>
          </el-icon>
          <span>Navigator Three</span>
        </el-menu-item>
        <el-menu-item index="4">
          <el-icon>
            <setting/>
          </el-icon>
          <span>Navigator Four</span>
        </el-menu-item>
      </el-menu>
    </el-col>
    <div style="flex: 1;">
      <router-view v-slot="{ Component }">
        <keep-alive>
          <component :is="Component" :key="route.fullPath"/>
        </keep-alive>
      </router-view>
    </div>
  </el-row>
</template>

<script lang="ts" setup>
import {useRoute} from 'vue-router'
import {
  Document,
  Menu as IconMenu,
  Setting, User,
} from '@element-plus/icons-vue'

const route = useRoute()
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>
<style scoped lang="scss">
.tac {
  width: 100%;
  height: 100%;

  flex-wrap: nowrap;

  & > div:first-child {
    flex: 0;
    width: 200px;

    & ul {
      height: 100%;
      border: none;
    }
  }

  & > div:last-child {
    flex: 1 !important;
    width: calc(100% - 200px);
    background: #ececec;
  }
}
</style>
